<template>
    <div class="app-container">
        <el-row :gutter="0">
            <!--专病数据-->
            <el-form class="formBox formBox1  searchForm" :model="queryParams" ref="queryForm" size="small" :inline="true"
                v-show="showSearch" label-width="68px">
                <el-form-item label="选择医院">
                    <department :isHospital="true" :isdepat="true" @refreshData="refreshData" deptWidth="180px"
                        ref="department" :isUserAll="true">
                    </department>
                </el-form-item>
                <el-form-item label="专病">
                    <el-select v-model="queryParams.diseaseClassifyIds" filterable placeholder="请选择专病名称" clearable
                        :collapse-tags="true" multiple style="width: 180px" @change="handleQuery">
                        <el-option v-for="item in classifyList" :key="item.diseaseClassifyId"
                            :label="item.diseaseClassifyName" :value="item.diseaseClassifyId" />
                    </el-select>
                </el-form-item>
                <el-form-item label="选择时间">
                    <el-date-picker v-model="dateRange" style="width: 190px;margin-right:10px;"
                        :picker-options="pickerOptions" value-format="yyyy-MM-dd" type="daterange" size="mini"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="handleQuery"
                        :clearable="false"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
                    <el-button icon="el-icon-printer" size="mini" type="success" @click="handleExport">导出</el-button>
                </el-form-item>
            </el-form>
            <div class="formBox searchForm" ref="statisticalTable">
                <el-collapse accordion style="border:none;width:100%;margin-bottom:10px;margin-top:4px;"
                    v-model="PlanactiveName">
                    <el-collapse-item title="专病统计表" style="border:none" name="1">
                        <!-- :summary-method="getSummaries" -->
                        <el-table border v-loading="loading" :data="tableLists" show-summary id="out-table" ref="table"
                            :height="statisticalTableH">

                            <!-- <el-table-column label="开始日期" align="center" prop="startTime" :show-overflow-tooltip="true" width="100"
                        fixed>
                        <template slot-scope="scope">
                            {{ dateRange[0] }}
                        </template>
                    </el-table-column>

                    <el-table-column label="结束日期" align="center" prop="endTime" :show-overflow-tooltip="true" width="100"
                        fixed>
                        <template slot-scope="scope">
                            {{ dateRange[1] }}
                        </template>
                    </el-table-column> -->
                            <el-table-column label="操作" align="center" prop="startTime" :show-overflow-tooltip="true"
                                width="120" fixed>
                                <template slot-scope="scope">
                                    <el-button size="mini" type="text" icon="el-icon-s-data"
                                        @click="scanParameters(scope.row)">治疗业务分析</el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="专病名称" align="center" prop="diseaseClassifyName"
                                :show-overflow-tooltip="true" width="160" fixed>

                            </el-table-column>
                            <el-table-column label="分期" align="center" prop="diseaseSerialization"
                                :show-overflow-tooltip="true" fixed>
                                <template slot-scope="scope">
                                    <span
                                        v-if="scope.row.diseaseSerialization == '[]' || scope.row.diseaseSerialization == undefined || scope.row.diseaseSerialization == null">-</span>
                                    <span v-else>{{ scope.row.diseaseSerialization }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="分型" align="center" prop="diseaseType" :show-overflow-tooltip="true"
                                fixed>
                                <template slot-scope="scope">
                                    <span
                                        v-if="scope.row.diseaseType == '[]' || scope.row.diseaseType == undefined || scope.row.diseaseType == null">-</span>
                                    <span v-else>{{ scope.row.diseaseType }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="诊断人次（人次）" align="center" prop="diagnosedNum"
                                :show-overflow-tooltip="true" width="130">

                            </el-table-column>
                            <el-table-column label="拍照人次（人次）" align="center" prop="photoNum" :show-overflow-tooltip="true"
                                width="130">

                            </el-table-column>
                            <el-table-column label="治疗人次（人次）" align="center" prop="treatmentNum"
                                :show-overflow-tooltip="true" width="130">

                            </el-table-column>
                            <el-table-column label="医疗开单总收入（元）" align="center" prop="totalExpenses"
                                :show-overflow-tooltip="true">

                            </el-table-column>
                            <el-table-column label="治疗开单总收入（元）" align="center" prop="treatmentExpenses"
                                :show-overflow-tooltip="true" width="200">

                            </el-table-column>
                        </el-table>
                    </el-collapse-item>
                </el-collapse>
                <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" /> -->
            </div>
            <div class="formBox">
                <el-form class="" :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
                    <el-form-item label="排序：">
                        <el-select v-model="queryParams.type" placeholder="排序方式" clearable filterable style="width: 160px"
                            @change="handleQuery">
                            <el-option v-for="dict in sortArr" :key="dict.value" :label="dict.label" :value="dict.value" />
                        </el-select>
                    </el-form-item>


                    <el-form-item>
                        <el-radio-group v-model="queryParams.sort" @input="handleQuery">
                            <el-radio :label="1">低到高</el-radio>
                            <el-radio :label="2">高到低</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item>
                        <el-button size="mini" @click="handleQuery">刷新</el-button>
                    </el-form-item>
                </el-form>
                <div class="echart-box">
                    <div id="treatmentAndIncome" style="width:100%;height:500px;cursor:pointer;">
                        <div v-if="tableLists.length == 0">
                            <img class="parent-img" src="@/assets/404_images/404_cloud.png" alt="404">
                            <div class="parent-text"> 暂无统计数据！</div>
                        </div>
                    </div>

                </div>
            </div>


        </el-row>

        <!-- 治疗业务统计弹窗 -->
        <el-dialog :title="diseaseAndtreatTitle" class="nopaddingDailog" :visible.sync="diseaseAndtreatDailog"
            @close="closeDiseaseAndtreatDailog" width="80%">
            <div class="formBox">
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-button icon="el-icon-printer" size="mini" type="success" @click="handleExport1"
                            style="margin-bottom:8px;">导出</el-button>
                        <el-table border v-loading="diseaseAndtreatTloading" show-summary :data="diseaseAndtreatTtableLists"
                            id="out-table1">
                            <el-table-column label="治疗业务名称" align="center" prop="planName" :show-overflow-tooltip="true"
                                width="160" fixed>
                            </el-table-column>
                            <el-table-column label="治疗人次（人次）" align="center" prop="number" :show-overflow-tooltip="true"
                                width="130">
                            </el-table-column>
                            <el-table-column label="治疗总收入（元）" align="center" prop="treatmentPrice"
                                :show-overflow-tooltip="true">

                            </el-table-column>
                        </el-table>
                    </el-col>
                </el-row>
            </div>


            <el-row style="margin-top:15px;">
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <div class="formBox">
                        <div id="treatmentAndIncome0" style="width:100%;height:300px;cursor:pointer;">
                            <div v-if="diseaseAndtreatTtableLists.length == 0">
                                <img class="parent-img" src="@/assets/404_images/404_cloud.png" alt="404">
                                <div class="parent-text"> 暂无统计数据！</div>
                            </div>
                        </div>
                    </div>

                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <div class="formBox">
                        <div id="treatmentAndIncome1" style="width:100%;height:300px;cursor:pointer;">
                            <div v-if="diseaseAndtreatTtableLists.length == 0">
                                <img class="parent-img" src="@/assets/404_images/404_cloud.png" alt="404">
                                <div class="parent-text"> 暂无统计数据！</div>
                            </div>
                        </div>
                    </div>
                </el-col>
            </el-row>

        </el-dialog>
    </div>
</template>

<script>
//引入安装的依赖
import * as XLSX from "xlsx";
import * as FileSaver from "file-saver";
import XLSXD from "xlsx-style";
import * as echarts from "echarts";
import {
    listClassify,
} from "@/api/system/classify";
import { deptNameList } from "@/api/system/dept";
import department from "@/views/components/department/index.vue";
import { statisticsDiseasesList, statisticsDistributionPlan } from "@/api/system/specialCom";
import {
    listPlan
} from "@/api/system/plan";
const chart2 = {
    title: {
        text: '治疗业务分布',
        left: 'center'
    },
    toolbox: {
        show: true,
        left: "5%",
        feature: {
            mark: { show: true },
            // dataView : {show: true, readOnly: false},
            // magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
            // restore: { show: true },
            saveAsImage: { show: true }
        }
    },
    tooltip: {
        trigger: 'item'
    },
    legend: {
        type: 'scroll',
        orient: 'vertical',
        right: 5,
        top: 20,
        bottom: 20,
    },
    series: [
        {
            name: '人次',
            left: '1%',
            right: "50%",
            type: 'pie',
            radius: '50%',
            color: ["#b6dd09", "red", "blue", "#2cdd09", "green", "orange", "#4c6d09", "#4c6785", "#4c6745", "#9c6745", "#9c6845"],
            data: [


            ],
            // name|{b}}
            label: {
                alignTo: 'none',
                formatter: '{per|{d}%} \n{time|{c} 人次}  ',
                edgeDistance: 60,
                lineHeight: 14,
                rich: {
                    name: {
                        fontSize: 12,
                    },
                    per: {
                        fontSize: 12,
                    },
                    time: {
                        fontSize: 12,
                        color: '#000'
                    }
                }
            },
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
}
const chart3 = {
    title: {
        text: '治疗业务分布',
        left: 'center'
    },
    toolbox: {
        show: true,
        left: "5%",
        feature: {
            mark: { show: true },
            // dataView : {show: true, readOnly: false},
            // magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
            // restore: { show: true },
            saveAsImage: { show: true }
        }
    },
    tooltip: {
        trigger: 'item'
    },
    legend: {
        // orient: 'horizontal',
        // left: 'center',
        // bottom: 0
        type: 'scroll',
        orient: 'vertical',
        right: 5,
        top: 20,
        bottom: 20,
    },
    series: [
        {
            name: '元',
            left: '1%',
            right: "50%",
            type: 'pie',
            radius: '50%',
            color: ["#b6dd09", "red", "blue", "#2cdd09", "green", "orange", "#4c6d09", "#4c6785", "#4c6745", "#9c6745", "#9c6845"],
            data: [


            ],
            label: {
                alignTo: 'none',
                formatter: '{per|{d}%} \n{time|{c} 元}',
                edgeDistance: 60,
                lineHeight: 14,
                rich: {
                    name: {
                        fontSize: 12,
                    },
                    per: {
                        fontSize: 12,
                    },
                    time: {
                        fontSize: 12,
                        color: '#000'
                    }
                }
            },
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
}
const treatmentAndIncomeOption = {
    title: {
        text: '治疗人次和收入表',
    },

    // 滚动条
    dataZoom: [
        {
            show: true,
            type: 'slider',
            zoomLock: true,
            // realtime: true,
            // start: 0,
            // end:30,
            startValue: 0,
            endValue: 5,
            xAxisIndex: [0],
            bottom: '0',
            left: '50',
            height: 15,
            borderColor: 'rgba(0,0,0,0)',
            textStyle: {
                color: 'transparent'
            }
        }
    ],
    label: {
        show: true, //开启显示数值
        position: 'top', //数值在上方显示
        textStyle: {  //数值样式
            //color: '#D1DBFF',   //字体颜色
            //fontSize: 14  //字体大小
        }
    },
    toolbox: {
        show: true,
        feature: {
            mark: { show: true },
            // dataView : {show: true, readOnly: false},
            magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
            restore: { show: true },
            saveAsImage: { show: true }
        }
    },
    legend: {
        // Try 'horizontal'
        orient: 'vertical',
        right: 0,
        top: 'center'
    },
    tooltip: {},
    dataset: {
        dimensions: ["diseaseClassifyName", "诊断人次", "治疗人次", '医疗开单总收入/万元', '治疗开单总收入/万元'],
        source: [

        ],
    },
    yAxis: { //xAxis
        nameTextStyle: {
            borderType: "dotted",
            color: 'red',

        }
    },
    grid: {
        bottom: 100
    },
    xAxis: {
        type: "category",
        padding: 10,

        axisLabel: {
            color: "red",
            rotate: 0,
            interval: 0,
            margin: 5,
            fontSize: 14,
            formatter(params) {
                var newParamsName = "";
                var paramsNameNumber = params.length;
                var provideNumber = 4;  //一行显示几个字
                var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
                if (paramsNameNumber > provideNumber) {
                    for (var p = 0; p < rowNumber; p++) {
                        var tempStr = "";
                        var start = p * provideNumber;
                        var end = start + provideNumber;
                        if (p == rowNumber - 1) {
                            tempStr = params.substring(start, paramsNameNumber);
                        } else {
                            tempStr = params.substring(start, end) + "\n";
                        }
                        newParamsName += tempStr;
                    }

                } else {
                    newParamsName = params;
                }
                return newParamsName;

            }
        }
    },
    series: [{ type: "bar", color: "#b6dd09", barWidth: "30" }, { type: "bar", color: "red", barWidth: "30" }, { type: "bar", color: "blue", barWidth: "30" }, { type: "bar", color: "#2cdd09", barWidth: "30" }],
};
export default {
    name: "doctorSum",
    dicts: [

    ],
    components: { department },
    data() {
        return {
            diseaseAndtreatTloading: false,
            diseaseAndtreatTtableLists: [],
            diseaseAndtreatDailog: false,
            diseaseAndtreatTitle: '',
            PlanactiveName: '',
            hospitalName: '',
            treatmentPlansList: [],
            sortArr: [
                {
                    value: 1,
                    label: '按诊断人次'
                },
                {
                    value: 2,
                    label: '按治疗人次'
                },
                {
                    value: 3,
                    label: '按医疗开单总收入'
                },
                {
                    value: 4,
                    label: '按治疗开单总收入'
                }
            ],
            classifyList: [],
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() > Date.now() - 8.64e6;  //如果没有后面的-8.64e6就是不可以选择今天的
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        const end = date;
                        const start = date;
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '前天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
                        const end = date;
                        const start = date;
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近1年',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            // 方案表格数据
            planList: null,

            tableLists: [],
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 日期范围
            dateRange: [],
            // 表单参数
            // form: {},
            form: {

            },
            pageNum: 1,
            pageSize: 10,
            deptNameLists: [],
            statisticalTableH: undefined,
            // 查询参数
            queryParams: {
                // pageNum: 1,
                // pageSize: 10,
                hospitalId: '',
                deptId: '',
                diseaseClassifyIds: [],
                sort: 2,//2 高到低 1 低到高
                type: 1,//1 诊断人次 2 治疗人次 3 医疗开单收入 4 治疗开单收入


            },
        };
    },
    watch: {},
    computed: {
        defaultTime: function () {//默认当月1号 到 现在
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            month = month > 9 ? month : "0" + month;
            day = day < 10 ? "0" + day : day;
            let day0 = '01';
            let today = year + "-" + month + "-" + day;
            let firtsDay = year + "-" + month + "-" + day0;
            return [firtsDay, today];
        },
    },
    async created() {

    },
    mounted() {
        this.dateRange = this.defaultTime
        this.changeHeight()
    },
    updated() {
        this.$nextTick(() => {
            this.$refs.table.doLayout()
        })
    },
    methods: {
        statisticsDistributionPlanEvent(id) {
            let that = this
            statisticsDistributionPlan({
                diseaseClassifyId: id,
                beginTime: that.dateRange[0],
                endTime: that.dateRange[1],
                ...that.queryParams
            }
            ).then((response) => {
                let data = response.data;
                let voLarr = [], voLarr1 = []
                data.forEach((ele) => {
                    let obj = {}

                    obj.name = ele.planName
                    obj.value = ele.number
                    voLarr.push(obj)
                })
                data.forEach((ele) => {
                    let obj = {}

                    obj.name = ele.planName
                    obj.value = ele.treatmentPrice
                    voLarr1.push(obj)
                })
                //左边饼图

                var treatmentAndIncomeChart0 = echarts.init(document.getElementById("treatmentAndIncome0"));
                chart2.title.text = '治疗人次'
                chart2.series[0].data = voLarr
                treatmentAndIncomeChart0.clear()
                treatmentAndIncomeChart0.setOption(chart2);
                //右边饼图

                var treatmentAndIncomeChart1 = echarts.init(document.getElementById("treatmentAndIncome1"));
                chart3.title.text = '治疗收入'
                chart3.series[0].data = voLarr1
                treatmentAndIncomeChart1.clear()
                treatmentAndIncomeChart1.setOption(chart3);
                this.diseaseAndtreatTtableLists = data;


            });
        },
        changeHeight() {
            if (this.$refs.statisticalTable) {
                const statisticalTableObj = this.$refs.statisticalTable.getBoundingClientRect();
                let h = statisticalTableObj.top + 80
                this.statisticalTableH = 'calc(100vh - ' + h + 'px)'
            } else {
                this.statisticalTableH = '500px'
            }
        },
        closeDiseaseAndtreatDailog() {// 关闭弹窗
            this.diseaseAndtreatDailog = false
        },
        scanParameters(row) {//查看治疗业务分析图
            console.log(row)
            this.diseaseAndtreatTitle = row.diseaseClassifyName + '的治疗业务分析'
            this.diseaseAndtreatDailog = true
            this.statisticsDistributionPlanEvent(row.diseaseClassifyId)

        },
        // 获取专病列表
        getClassifyList() {
            listClassify(
                {
                    pageNum: 1,
                    pageSize: 9999,
                    status: 0
                }
            ).then((response) => {
                this.classifyList = response.rows;

            });
        },
        getSummaries(param) {
            let that = this
            const { columns, data } = param;
            const sums = [];
            // console.log(columns)
            // console.log(data)
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计';
                    return;
                }
                if (index === 1) {
                    return;
                }
                let indexof = parseInt((index - 3) / 2)
                // console.log(indexof)

                const values = data.map(item => Number(item.treatmentCount[indexof][column.property]));
                // console.log(values)
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index] += '';
                } else {
                    sums[index] = '';
                }


            });
            return sums;
        },

        handleExport() {
            let tables = document.getElementById('out-table').cloneNode(true) // 重点
            if (tables.querySelector(".el-table__fixed")) {
                tables.removeChild(tables.querySelector(".el-table__fixed")) // 重点
            }
            let wb = XLSX.utils.table_to_book(tables, { sheet: '专病统计' })
            this.setExlStyle(wb['Sheets']['专病统计'])
            //合并单元格边框补齐
            this.addRangeBorder(wb['Sheets']['专病统计']['!merges'], wb['Sheets']['专病统计'])
            var ws = XLSXD.write(wb, {
                type: "buffer"
            });
            try {
                FileSaver.saveAs(
                    new Blob([ws], { type: "application/octet-stream" }),
                    `专病统计_${this.dateRange[0]}~${this.dateRange[1]}.xlsx`
                );
            } catch (e) {
                if (typeof console !== "undefined") console.log(e, ws);
            }
            return ws;

        },
        handleExport1() {
            let tables = document.getElementById('out-table1').cloneNode(true) // 重点
            if (tables.querySelector(".el-table__fixed")) {
                tables.removeChild(tables.querySelector(".el-table__fixed")) // 重点
            }
            let wb = XLSX.utils.table_to_book(tables, { sheet: '专病治疗项目分析统计' })
            this.setExlStyle(wb['Sheets']['专病治疗项目分析统计'])
            //合并单元格边框补齐
            this.addRangeBorder(wb['Sheets']['专病治疗项目分析统计']['!merges'], wb['Sheets']['专病治疗项目分析统计'])
            var ws = XLSXD.write(wb, {
                type: "buffer"
            });
            try {
                FileSaver.saveAs(
                    new Blob([ws], { type: "application/octet-stream" }),
                    `${this.diseaseAndtreatTitle}统计_${this.dateRange[0]}~${this.dateRange[1]}.xlsx`
                );
            } catch (e) {
                if (typeof console !== "undefined") console.log(e, ws);
            }
            return ws;

        },
        setExlStyle(data) {
            let borderAll = {//单元格外侧框线
                top: {
                    style: 'thin',
                },
                bottom: {
                    style: 'thin'
                },
                left: {
                    style: 'thin'
                },
                right: {
                    style: 'thin'
                }
            };
            data['!cols'] = [];
            for (let key in data) {
                if (data[key] instanceof Object) {
                    data[key].s = {
                        border: borderAll,
                        alignment: {
                            horizontal: 'center',//水平居中对齐
                            vertical: 'center'
                        },
                        font: {
                            sz: 11
                        },
                        bold: true,
                        numFmt: 0
                    }
                    data['!cols'].push({ wpx: 150 });
                }
            }
            return data;
        },
        addRangeBorder(range, ws) {
            let arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
            if (range == undefined || range == null) {
                return
            }
            range.forEach(item => {
                let startRowNumber = Number(item.s.c),
                    endRowNumber = Number(item.e.c);
                for (let i = startRowNumber; i <= endRowNumber; i++) {
                    for (let j = Number(item.s.r) + 1; j <= Number(item.e.r); j++) {
                        ws[`${arr[i]}${j + 1}`] = { s: { border: { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } } } };
                    }
                }

            })
            return ws;

        },

        // 回显医院及门诊
        getdeptNameList() {
            deptNameList().then((response) => {
                this.deptNameLists = response.data;
            });
        },
        refreshData(data) {
            console.log(data)
            if (data.hospitalId) {
                this.queryParams.hospitalId = data.hospitalId
                this.queryParams.deptId = data.deptId

                this.getList()
            } else {
                this.queryParams.hospitalId = ''
                this.loading = false
            }
            this.getClassifyList()

        },
        strNumSize(tempNum) {//判断长度
            var stringNum = tempNum.toString();
            var index = stringNum.indexOf(".");
            var newNum = stringNum;
            if (index != -1) {
                newNum = stringNum.substring(0, index);
            }
            return newNum.length;
        },
        unitConvert(num, type) {
            var moneyUnits = ["元", "万元", "亿元", "万亿"];
            var dividend = 10000;
            var curentNum = num;
            //转换数字
            var curentUnit = moneyUnits[0];
            //转换单位
            if (type == 1) {
                curentNum = curentNum / dividend;
                curentUnit = moneyUnits[1];
            } else {
                for (var i = 0; i < 4; i++) {
                    curentUnit = moneyUnits[i];
                    if (this.strNumSize(curentNum) < 5) {
                        break;
                    }
                    curentNum = curentNum / dividend;
                }
            }

            var m = { num: 0, unit: "" };
            m.num = curentNum.toFixed(2);
            m.unit = curentUnit;
            return m;
        },
        getWNum(numStr) {
            var numBER = Number(numStr)
            var totalAmount = this.unitConvert(numBER, 1);
            return totalAmount.num;//+ totalAmount.unit;
        },
        getList() {
            let that = this
            that.loading = true;
            if (that.queryParams.hospitalId == undefined || that.queryParams.hospitalId == "" || that.queryParams.hospitalId == null) {
                this.$modal.msgError("请选择医院!");
                that.loading = false;
                return false
            }
            let params = {
                beginTime: that.dateRange[0],
                endTime: that.dateRange[1],
                ...that.queryParams
            }
            statisticsDiseasesList(params).then((response) => {
                if (response.code == 200) {
                    let data = response.data;
                    let voLists = data.voList

                    that.tableLists = voLists
                    let voLarr = []
                    voLists.forEach(item => {
                        let obj = {}
                        let price = that.getWNum(item.totalExpenses)
                        let price1 = that.getWNum(item.treatmentExpenses)
                        obj.totalExpenses = price
                        obj.treatmentExpenses = price1
                        obj.diagnosedNum = item.diagnosedNum
                        obj.treatmentNum = item.treatmentNum
                        obj.diseaseClassifyName = item.diseaseClassifyName
                        voLarr.push(obj)
                    })
                    if (voLarr && voLarr.length > 5) {
                        treatmentAndIncomeOption.dataZoom[0].show = true
                    } else {
                        treatmentAndIncomeOption.dataZoom[0].show = false
                    }
                    // arr = arr.filter(v => v.num < 20).map(v => v.num)
                    treatmentAndIncomeOption.title.text = that.dateRange[0] + ' ~ ' + that.dateRange[1] + '专病统计'
                    var treatmentAndIncomeChart = echarts.init(document.getElementById("treatmentAndIncome"));
                    var a = JSON.stringify(voLarr).replace(/diagnosedNum/g, "诊断人次").replace(/treatmentNum/g, "治疗人次").replace(/totalExpenses/g, "医疗开单总收入/万元").replace(/treatmentExpenses/g, "治疗开单总收入/万元");

                    treatmentAndIncomeOption.dataset.source = JSON.parse(a)
                    if (voLarr.length > 0) {
                        treatmentAndIncomeChart.clear()
                        treatmentAndIncomeChart.setOption(treatmentAndIncomeOption);
                    } else {
                        treatmentAndIncomeChart.clear()
                        treatmentAndIncomeChart.setOption({
                            title: {
                                text: '暂无统计数据!',
                                x: 'center',
                                y: 'center',
                                textStyle: {
                                    fontSize: 16,
                                    color: '#909399',
                                    fontWeight: 'normal'
                                }
                            }
                        })
                    }
                }
                that.loading = false;
            });

        },
        getTbaleCloum(arrAList, id, obj) {
            let that = this
            let item = arrAList.find(v => v.sPlanId == id)
            if (item) {
                return item
            } else {
                return obj
            }
        },
        // 真实序号计算（计算分页影响）
        getIndex(index) {
            return (this.pageNum - 1) * this.pageNum + index + 1;
        },

        // 取消按钮
        cancel() {

        },
        // 表单重置
        reset() {

        },
        /** 搜索按钮操作 */
        handleQuery() {

            // this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.resetForm("queryForm");
            if (this.$refs.department) {
                this.$refs.department.reset()
            }
        },
    },
};
</script>
<style scoped lang="scss">
::v-deep .statisticalTable .el-table .cell {
    font-size: 12px;
}

.echart-box {
    cursor: pointer;
    margin-top: 20px;
}

.parent-img {
    width: 200px;
    height: 200px;
    display: block;
    margin: 10px auto;
}

.parent-text {
    color: #999;
    text-align: center;
}
</style>
